package com.example.demoproduct.service;

import com.example.demoapi.base.BaseInfoEntity;
import com.example.demoapi.base.BaseInfoService;
import com.example.demoapi.product.Product;
import com.example.demoapi.product.ProductService;
import com.example.registerstarter.anno.RemoteReference;
import com.example.registerstarter.anno.RemoteService;
import org.springframework.beans.factory.annotation.Value;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author：kangxuan
 * @date：2024/9/30 11:48 AM
 * @desc:
 */
@RemoteService
public class ProductServiceImpl implements ProductService {

    @Value("${server.port}")
    private String port;

    @RemoteReference
    private BaseInfoService baseInfoService;

    private final Map<String, Product> DB = new HashMap<>();
    @Override
    public void addProduct(Product p) {
        DB.put(p.getName(), p);
    }

    @Override
    public List<Product> getList() {
        return List.of(new Product("product1", "product1", "1"));
    }

    @Override
    public List<Product> getList(String name, Product product) {
        System.out.println(name);
        System.out.println(product);

        BaseInfoEntity baseInfo = baseInfoService.getBaseInfo("baseInfo");

        product.setName(port);
        product.setDescription(baseInfo.getName());
        return List.of(product);
    }
}
